home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / nrd34.zip / STRUTIL.PAS < prev    next >
Pascal/Delphi Source File  |  1990-12-01  |  2KB  |  118 lines

  1. unit strutil;
  2.  
  3.  { {STRUTIL.PAS --- rev 1.0
  4.        Author:  Tom Whiteside
  5.                 11505 Oak View Dr
  6.                 Austin, TX 78759
  7.                 (512) 258-5924
  8.  
  9.  
  10.        Purpose: Various string utilities.  These were
  11.                 developed years ago for Apple Pascal and subsequently ported
  12.                 to IBM Pascal then Turbo Pascal to migrate other code along.
  13.                 Their main asset is their use by many lines of code and my
  14.                 familiarity with them. 
  15.  rev 1.0 }
  16.  
  17. interface
  18.  
  19.   type lstring = string[255];
  20.  
  21.   procedure int_to_str(num:integer; var strg:lstring);
  22.   procedure str_to_int(strg:lstring; var num:integer);
  23.   procedure rt_just(var t:lstring; len:integer);
  24.   procedure lf_just(var t:lstring; len:integer);
  25.   procedure date_format(var month,day,year:lstring);
  26.  
  27.  
  28. implementation
  29. uses intutil, dos;
  30.  
  31.  
  32.  
  33.   { convert int to string }
  34.  
  35.   procedure int_to_str;
  36.   var tstrg:string[255];
  37.       s:string[1];
  38.       len,i:integer;
  39.       done:boolean;
  40.   begin
  41.     strg:='';
  42.     s:=' ';
  43.     i:=0;
  44.     done:=FALSE;
  45.     while (i < 255) and not done do
  46.       begin
  47.     s[1]:=chr((num mod 10) + ord('0'));
  48.     strg:=concat(s,strg);
  49.     num:=num div 10;
  50.     done:=num = 0;
  51.     i:=i + 1;
  52.       end;
  53.   end;
  54.  
  55.  
  56.   { convert string to integer }
  57.  
  58.   procedure str_to_int;
  59.   var i,t,len:integer;
  60.       ch:char;
  61.   begin
  62.     num:=0;
  63.     len:=length(strg);
  64.     if len > 4 then num:=32767
  65.     else
  66.       begin
  67.     for i:=1 to len do
  68.       begin
  69.         ch:=strg[i];
  70.         if ch in ['0'..'9'] then
  71.           begin
  72.         t:=ord(ch) - ord('0');
  73.         num:=num * 10 + t;
  74.           end;
  75.       end;
  76.       end;
  77.   end;
  78.  
  79.  
  80.   procedure rt_just;
  81.   begin
  82.     while length(t) < len do t:=concat(' ',t);
  83.   end;
  84.  
  85.   procedure lf_just;
  86.   begin
  87.     while length(t) < len do t:=concat(t,' ');
  88.   end;
  89.  
  90.  
  91.   procedure date_format;
  92.   var tstrg:string[8];
  93.       dateval:string[255];
  94.       yr,mnth,dy,dyofweek:word;
  95.   begin
  96.     getdate(yr,mnth,dy,dyofweek);
  97.     case mnth of
  98.       1: month:='January';
  99.       2: month:='February';
  100.       3: month:='March';
  101.       4: month:='April';
  102.       5: month:='May';
  103.       6: month:='June';
  104.       7: month:='July';
  105.       8: month:='August';
  106.       9: month:='September';
  107.      10: month:='October';
  108.      11: month:='November';
  109.      12: month:='December';
  110.      else month:='???'
  111.     end;
  112.     int_to_str(dy,day);
  113.     int_to_str(yr,year);
  114.   end;
  115.  
  116. begin
  117. end.
  118.